package com.neuedu.javase.inner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-28 8:48
 * 描述 :
 */
public class Runner {



    static class InnerComparator implements  Comparator<Integer>{

        @Override
        public int compare(Integer o1, Integer o2) {
            return o1 - o2;
        }
    }

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(new Integer(20));
        list.add(new Integer(26));
        list.add(new Integer(21));
        list.add(new Integer(28));
        for (Object o : list) {
            System.out.println(o);
        }
        System.out.println("====================");

        
        //工具类 java.util.Collectionos.sort(list ,排序规则的对象)  排序
//        Comparator comparator = new MyComparator();
//        Collections.sort(list,comparator);







        //内部类  可以不用单独定义 Comparator 子类 放弃
//        Collections.sort(list,new InnerComparator());




        //内部类  可以不用单独定义 Comparator 子类 放弃
        Comparator comparator = new Comparator<Integer>(){

            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        };
        Collections.sort(list,comparator);

        for (Object o : list) {
            System.out.println(o);
        }


    }






}
